package com.score.student.controller;

import com.score.student.domain.dto.UserAddDTO;
import com.score.student.domain.dto.UserLoginDTO;
import com.score.student.domain.dto.UserPageDTO;
import com.score.student.domain.dto.UserUpdateDTO;
import com.score.student.domain.po.User;
import com.score.student.domain.result.Result;
import com.score.student.domain.vo.UserLoginVO;
import com.score.student.domain.vo.UserVO;
import com.score.student.service.IUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author
 * @version 1.0
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController {

    private final IUserService iUserService;

    @PostMapping("/login")
    public Result<UserLoginVO> userLogin(@RequestBody UserLoginDTO userLoginDTO){
        log.info("进行了登录操作{}",userLoginDTO);
        UserLoginVO userLoginVO = iUserService.login(userLoginDTO);
        log.info("{}",userLoginVO);
        return Result.success(userLoginVO);
    }

    @GetMapping("/page")
    public Result<UserVO> page(UserPageDTO userPageDTO){
        log.info("查询所有学生信息没有分页");
        UserVO userVO = iUserService.queryAllStudent(userPageDTO);
        return Result.success(userVO);
    }

    @GetMapping("/{id}")
    public Result<User> queryById(@PathVariable Integer id){
        log.info("用于更改时的数据回写");
        User user = iUserService.getById(id);
        return Result.success(user);
    }

    @PostMapping("/add")
    public Result add(@RequestBody UserAddDTO userAddDTO){
        log.info("添加学生");
        iUserService.add(userAddDTO);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody UserUpdateDTO userUpdateDTO){
        log.info("更新学生信息");
        iUserService.updateByUserId(userUpdateDTO);
        return Result.success();
    }

    @DeleteMapping("/deleteById")
    public Result delete(Integer id){
        log.info("删除学生id={}",id);
        iUserService.removeById(id);
        return Result.success();
    }

}

